package com.wc.alorithm_blue_bridge._图论.蓝桥公园;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;

/**
 * @Author congege
 * @Description
 * 蓝桥公园
 * https://www.lanqiao.cn/problems/1121/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 * @Date Created in 2023/11/3-10:26
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        long INF = (long) Math.pow(10, 9) * (n - 1) + 1;
        // map[i][j] 表示从i 到 j 的最短路径
        long[][] map = new long[n + 1][n + 1];

        for (long[] row : map) {
            Arrays.fill(row, INF);
        }
        while (m-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            int w = sc.nextInt();
            map[i][j] = map[j][i] = Math.min(map[i][j], w);
        }

        // floyd
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (j == i) {
                    continue;
                }
                for (int k = 1; k <= n; k++) {
                    map[j][k] = Math.min(map[j][k], map[j][i] + map[i][k]);
                }
            }
        }

        StringBuffer ans = new StringBuffer();
        while (q-- > 0) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            if (map[i][j] == INF) {
                ans.append(-1);
//                System.out.println(-1);
            } else if (i == j) {
                ans.append(0);
//                System.out.println(0);
            } else {
                ans.append(map[i][j]);
//                System.out.println(map[i][j]);
            }
            ans.append('\n');
        }
        System.out.print(ans);

    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
